/**
 * Created by zhouli on 18/2/2
 * Email li.zhou@huilianyi.com
 * 选择多个部门或者多个人
 * 用于人员组，成本中心项，部门批量调整等
 * 回调函数中返回选择了部门对象、人员对象
 */
import React from 'react';
import {connect} from 'react-redux';
import {Modal, Input, Icon, Button} from 'antd';
import DepTreeWithPerson from 'components/template/select-depment-or-person/dep-tree-with-person';
import SelectPersonService from 'components/template/select-depment-or-person/select-depment-or-person.service';
import OrgSearchList from 'components/template/select-depment-or-person/org-search-list';
import {deepFullCopy, messages} from "share/common";
import 'styles/components/template/select-depment-or-person/select-depment-or-person.scss';
import Chooser from 'components/chooser';
const treeData = [];

class SelectDepOrPerson extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      depCompany: {},
      userDepName: '',
      visible: false,
      treeData: treeData,//部门树数据
      selectedKeys: [],//当前被选中的部门或者人
      selectedKeysDepData: [],//当前被选中的部门或者人的数据
      selectedKeysDepDataFromSearch: [],//当前被选中的部门或者人的数据:是搜索出来的结果
      //上面两个属性要注意，从树里面选择的节点，与从搜索结果选择的节点不一样，需要单独处理
      loading: true,
      expandedKeys: [],
      autoExpandParent: true,
      isSearchOver: false,//是否正在搜索
      //组织架构搜索结果
      searchList: {
        depList: [],
        personList: []
      }
    };
  }
  //显示模态框，准备数据
  showModal = () => {
    SelectPersonService.setIsLoadingPerson(!this.props.onlyDep);
    let _selected = this.props.selectedDeps.concat(this.props.selectedPersons);
    let selectedKeys = [];
    _selected.map(item => {
      let key = item.userOID ? item.userOID : item.departmentOID;
      selectedKeys.push(key);
    })
    this.setState({
      depCompany: this.props.enableDepCompany === "OPEN" ? deepFullCopy(this.props.depCompany):{},
      selectedKeys,
      selectedKeysDepData: [],
      selectedKeysDepDataFromSearch: _selected,//传入已经选择来的
      visible: true,
    },()=>{
      const { depCompany } = this.state;
      //显示模态框的时候再加载
      this.getTenantAllDep(this.props.flagDep, depCompany);
    });
  }
  handleOk = (e) => {
    const { selectedKeysDepData } = this.state;
    const { depResList, personResList,onConfirm } = this.props;
    if (!depResList && !personResList) {
      let data = this.getResArrObjData(selectedKeysDepData);
      onConfirm && onConfirm(this.unique(data));
    } else {
      let data = this.getResObjData(selectedKeysDepData, depResList, personResList);
      onConfirm && onConfirm(this.uniqueObj(data));
    }
    this.setState({
      visible: false,
    });
  }
  //去重,有人员与部门实体
  uniqueObj = (obj) => {
    let _obj = {};
    _obj.depList = this.unique(obj.depList);
    _obj.personList = this.unique(obj.personList);
    return _obj
  }
  //去重，单一实体
  unique = (arr) => {
    let obj = {},res = [];
    arr.map((item,index)=>{
      let id = item.userOID ? item.userOID : item.departmentOID;
      if(obj[id]){
        //如果已经有过相同id，直接去掉
        arr.splice(index,1);
      }else {
        obj[id] = true;
        res.push(item)
      }
    });
    return res;
  };
  /*
  * 获取对象的列表
  * */
  getResArrObjData(data) {
    let arr = [];
    if (data.length < 1) {
      arr = arr.concat(this.state.selectedKeysDepDataFromSearch);
      return arr;
    } else {
      for (let i = 0; i < data.length; i++) {
        arr.push(data[i].props.dataRef.originData)
      }
      arr = arr.concat(this.state.selectedKeysDepDataFromSearch);
      return arr;
    }
  }
  /*
  * 根据传入的配置获取对象的列表
  * 点击确定不能直接把选择的部门与人员返回出去
  * 需要根据配置整理数据，
  * 1.只返回人员实体列表，或者人员某几个属性列表
  * 2.只返回部门实体列表，或者部门某几个属性列表
  * 3.返回人员与部门两个实体列表，或者人员与部门某几个属性 两个列表
  * */
  getResObjData(data, depList, personList) {
    let obj = {
      depList: [],
      personList: []
    };
    if (data.length < 1 && this.state.selectedKeysDepDataFromSearch.length < 1) {
      return obj;
    } else {
      //树节点
      for (let i = 0; i < data.length; i++) {
        if (data[i].props.dataRef.originData.userOID) {
          //如果是人
          if (personList.length > 0) {
            let item = {};
            for (let j = 0; j < personList.length; j++) {
              item[personList[j]] = data[i].props.dataRef.originData[personList[j]];
            }
            obj.personList.push(item);
          } else {
            obj.personList.push(data[i].props.dataRef.originData);
          }
        } else {
          //如果是部门
          if (depList.length > 0) {
            let item = {};
            for (let j = 0; j < depList.length; j++) {
              item[depList[j]] = data[i].props.dataRef.originData[depList[j]];
            }
            obj.depList.push(item);
          } else {
            obj.depList.push(data[i].props.dataRef.originData);
          }
        }
      }
      // 搜索节点
      if (this.state.selectedKeysDepDataFromSearch.length > 0) {
        let data = this.state.selectedKeysDepDataFromSearch;
        for (let i = 0; i < data.length; i++) {
          if (data[i].userOID) {
            //如果是人
            if (personList.length > 0) {
              let item = {};
              for (let j = 0; j < personList.length; j++) {
                item[personList[j]] = data[i][personList[j]];
              }
              obj.personList.push(item);
            } else {
              obj.personList.push(data[i]);
            }
          } else {
            //如果是部门
            if (depList.length > 0) {
              let item = {};
              for (let j = 0; j < depList.length; j++) {
                item[depList[j]] = data[i][depList[j]];
              }
              obj.depList.push(item);
            } else {
              obj.depList.push(data[i]);
            }
          }
        }
      }
      return obj;
    }
  }
  handleCancel = (e) => {
    if (this.props.onCancel) {
      this.props.onCancel();
    }
    this.setState({
      visible: false,
    });
  }
  afterClose = () => {
    this.setState({
      userDepName: '',
      expandedKeys: [],
    });
  }

  /*
  * 查询所有集团部门
  * 如果是查询岗位信息，就是另一个接口
  * */
  getTenantAllDep(flag, depCompany) {
    let usersP = null;
    if(this.props.searchType){
      usersP = SelectPersonService.getTenantAllDepPosition(flag, depCompany.companyId, !!depCompany.companyId)
    }else {
      usersP = SelectPersonService.getTenantAllDep(flag, depCompany.companyId, !!depCompany.companyId)
    }
    usersP.then((response) => {
        this.setState({
          treeData: response,
        })
      })
  }
  /*
   * 通过部门 oid 查询子部门
   * 如果是查询岗位信息，就是另一个接口，是通过部门 id，
   * */
  getChildDepByDepOID(Dep, parentNode, depCompany) {
    let usersP = null;
    if(this.props.searchType){
      usersP = SelectPersonService.getChildDepByDepOIDPosition(Dep, parentNode, this.props.flagDep, depCompany.companyId, !!depCompany.companyId)
    }else {
      usersP = SelectPersonService.getChildDepByDepOID(Dep, parentNode, this.props.flagDep, depCompany.companyId, !!depCompany.companyId)
    }
    usersP.then((response) => {
        this.setState({
          treeData: response
        });
      })
  }

  /*
  * 通过部门 oid 查询部门下面的员工:挂载到树
  * 如果是查询岗位信息，就是另一个接口，是通过部门 id，查询部门下面的员工：挂载到树
  * */
  getDepTreeUserByDepOID(Dep, parentNode, depCompany) {
    this.setState({loading: true});
    let params = {page: 0, size: 10000};
    //查人需要根据是否是公司模式或者严格模式
    if (this.props.strictMode && !this.props.tenantMode) {
      params.roleType = "";
      params.companyOID = this.props.company.companyOID;
      if (this.props.loadCompanyOID) {
        params.companyOID = this.props.loadCompanyOID;
      }
    }
    if(depCompany && depCompany.companyOID){
      params.companyOID = depCompany.companyOID;
    }
    let usersP = null;
    if(this.props.searchType){
      usersP = SelectPersonService.getDepTreeUserByDepOIDPosition(Dep, params, parentNode, this.props.externalParams)
    }else {
      usersP = SelectPersonService.getDepTreeUserByDepOID(Dep, params, parentNode, this.props.externalParams)
    }
    usersP.then((response) => {
      this.getChildDepByDepOID(Dep, parentNode, depCompany);
      this.setState({
        loading: false,
        treeData: response
      });
    })
  }

  //获取是人的节点：过滤掉部门节点
  getPersonSelected = (nodes) => {
    let data = {
      nodes: [],
      keys: []
    }
    for (let i = 0; i < nodes.length; i++) {
      if (nodes[i].props.dataRef.type !== "DEP") {
        data.nodes.push(nodes[i]);
        data.keys.push(nodes[i].key);
      }
    }
    return data;
  }

  //点击部门树的时候，如果这个节点已经在搜索结果中并且被选择，就需要移除
  removeSelectedKeysDepDataFromSearch(node) {
    let key = node.props.dataRef.key;
    let list = this.state.selectedKeysDepDataFromSearch;
    let newList = [];
    for (let i = 0; i < list.length; i++) {
      let oid = list[i].userOID ? list[i].userOID : list[i].departmentOID;
      if (oid !== key) {
        newList.push(list[i]);
      }
    }
    this.setState({
      selectedKeysDepDataFromSearch: newList
    })
  }
  // 点击被选择
  onSelect = (selectedKeys, info) => {
    //如果只能单选，直接把最后点击的加入，其他就不要
    if (!this.props.multiple) {
      this.setState({
        selectedKeys: [],
        selectedKeysDepData: [],
        selectedKeysDepDataFromSearch: []
      }, () => {
        this.onSelectAfter(selectedKeys, info);
      });
    } else {
      this.onSelectAfter(selectedKeys, info);
    }
  }
  onSelectAfter = (selectedKeys, info) => {
    // 如果搜索结果列表中有，需要把搜索结果列表中删除
    this.removeSelectedKeysDepDataFromSearch(info.node);
    if (this.props.onlyPerson) {
      //如果只能选择人
      let personSelected = this.getPersonSelected(info.selectedNodes);
      this.setState({
        selectedKeys: personSelected.keys,
        selectedKeysDepData: personSelected.nodes
      });
    } else {
      /*
      * 部门与人都可以选择
      * 有了部门关联公司，树节点不能与右边被选择了的数据进行绑定，
      * 否则出现，公司过滤出另外一个部门树，会直接清除已经选择了的数据
      * 这边写一个 connectNodes 方法，求并集已经选择过的与再次从过滤的树选择
      * */
      let selectedKeysDepData = info.selectedNodes;
      this.setState({
        selectedKeys: selectedKeys,
        selectedKeysDepData
      });
    }
  }
  // 移除已经选择了的
  unSelect = (oid) => {
    const {selectedKeys, selectedKeysDepData} = this.state;
    let removedSelectedKeys = [];
    let removedSelectedKeysDepData = [];
    for (let i = 0; i < selectedKeys.length; i++) {
      if (selectedKeys[i] !== oid) {
        removedSelectedKeys.push(selectedKeys[i])
      }
    }
    for (let i = 0; i < selectedKeysDepData.length; i++) {
      if (selectedKeysDepData[i].key !== oid) {
        removedSelectedKeysDepData.push(selectedKeysDepData[i])
      }
    }
    this.setState({
      selectedKeys: removedSelectedKeys,
      selectedKeysDepData: removedSelectedKeysDepData
    });
  }
  // 点击展开的时候
  onExpand = (expandedKeys, {expanded, node}) => {
    if (expanded && !SelectPersonService.checkChildHasLoad(node.props.dataRef)) {
      //如果只展示到部门
      const { depCompany } = this.state;
      if (this.props.onlyDep) {
        this.getChildDepByDepOID(node.props.dataRef.originData, node.props.dataRef, depCompany);
      } else {
        this.getDepTreeUserByDepOID(node.props.dataRef.originData, node.props.dataRef, depCompany);
      }
    }
    this.setState({
      expandedKeys,
      autoExpandParent: false,
    });
  }
  //搜索人或者部门置空
  emitEmpty = () => {
    this.userNameDepInput.focus();
    this.setState({userDepName: ''});
  }
  /*
  * 搜索人或者部门
  * 如果是岗位信息，需要另一个接口 searchDepV2Position
  * */
  onChangeUserDepName = (e) => {
    if (e.target.value && e.target.value.length && e.target.value.length > 0) {
      this.setState({
        userDepName: e.target.value,
        isSearchOver: false
      });
      let usersP = null;
      if(this.props.searchType){
        usersP = SelectPersonService.searchDepV2Position(e.target.value, this.props.externalParams,this.state.depCompany)
      }else {
        usersP = SelectPersonService.searchDepV2(e.target.value, this.props.externalParams,this.state.depCompany)
      }
      usersP.then((response) => {
          let searchList = {
            depList: response.data.departments,
            personList: response.data.users
          };
          this.setState({
            searchList: searchList,
            isSearchOver: true
          });
        })
    } else {
      this.setState({
        userDepName: "",
      });
    }
  };
  //搜索结果的列表被点击
  searchListOnClicked = (item) => {
    let oid = item.userOID ? item.userOID : item.departmentOID;
    //如果只能单选，直接把最后点击的加入，其他就不要
    if (!this.props.multiple) {
      let key = item.userOID ? item.userOID : item.departmentOID;
      this.setState({
        userDepName: this.props.isClickSearchHide ? "" : this.state.userDepName,
        selectedKeys: [key],
        selectedKeysDepData: [],
        selectedKeysDepDataFromSearch: [item]
      });
      return;
    }
    if (this.checkNodeHasSelected(oid)) {
      //这里还涉及到一个去重，就是已经从部门树中选择了的节点，这个函数就不需要再走下去了
      this.setState({
        userDepName: this.props.isClickSearchHide ? "" : this.state.userDepName,
      });
    } else {
      let list = this.state.selectedKeysDepDataFromSearch;
      list.push(item);
      let selectedKeys = this.state.selectedKeys;
      let key = item.userOID ? item.userOID : item.departmentOID;
      selectedKeys.push(key);
      this.setState({
        userDepName: this.props.isClickSearchHide ? "" : this.state.userDepName,
        selectedKeys,
        selectedKeysDepDataFromSearch: list
      });
    }
  };
  //检查节点是否已经有了:如果有就返回true
  checkNodeHasSelected(oid) {
    for (let i = 0; i < this.state.selectedKeys.length; i++) {
      if (oid === this.state.selectedKeys[i]) {
        return true
      }
    }
    for (let i = 0; i < this.state.selectedKeysDepDataFromSearch.length; i++) {
      let item = this.state.selectedKeysDepDataFromSearch[i];
      let key = item.userOID ? item.userOID : item.departmentOID;
      if (oid === key) {
        return true
      }
    }
    return false;
  }

  unSelectPersonFromTree = (oid) => {
    //移除一个人，还需要移除在部门树上的选择状态
    const {selectedKeys} = this.state;//当前被选中的部门或者人
    for (let i = 0; i < selectedKeys.length; i++) {
      if (selectedKeys[i] === oid) {
        selectedKeys.splice(i, 1);
      }
    }
    this.setState({
      //必须得深拷贝重新设置状态
      selectedKeys: [...selectedKeys],
    });
  };

  // 移除已经选择了的:针对搜索结果
  unSelectFromSearch(oid) {
    let removedFromSearch = [];
    let list = this.state.selectedKeysDepDataFromSearch;
    for (let i = 0; i < list.length; i++) {
      if (list[i].userOID) {
        //人
        if (list[i].userOID !== oid) {
          removedFromSearch.push(list[i])
        }
      } else {
        // 部门
        if (list[i].departmentOID !== oid) {
          removedFromSearch.push(list[i])
        }
      }
    }
    this.setState({
      selectedKeysDepDataFromSearch: removedFromSearch
    }, () => {
      this.unSelectPersonFromTree(oid);
    });
  }

  //渲染部门树或者搜索结果
  renderOrgTreeOrSearchList = (e) => {
    const {searchList, userDepName, isSearchOver, treeData, selectedKeys, expandedKeys, autoExpandParent} = this.state;
    const {multiple, onlyDep, onlyPerson} = this.props;
    if (userDepName.length > 0) {
      return <div>
        <OrgSearchList
          searchType={this.props.searchType}
          multiple={multiple}
          selectedHandle={this.searchListOnClicked}
          searchList={searchList}
          onlyDep={onlyDep}
          onlyPerson={onlyPerson}
          isSearchOver={isSearchOver}
        />
      </div>
    } else {
      return <div>
        <DepTreeWithPerson
          multiple={this.props.multiple}
          treeData={treeData}
          selectedKeys={selectedKeys}
          expandedKeys={expandedKeys}
          autoExpandParent={autoExpandParent}
          onSelect={this.onSelect}
          onExpand={this.onExpand}
        />
      </div>
    }
  }

  //渲染从搜索结果中选择的人或者部门
  renderSelectedFromSearch(list, selectedKeysDepData) {
    //item是否在list里面
    function _isInSelected(list, item) {
      for (let i = 0; i < list.length; i++) {
        if (item === list[i].key) {
          return true
        }
      }
      return false
    }

    if (list.length < 1) {
      return <div/>
    } else {
      return list.map((item) => {
        if (item.userOID) {
          if (_isInSelected(selectedKeysDepData, item.userOID)) {
          } else {
            return <div className="selected-person-item" key={item.userOID}>
              <div className="type-icon">
                <Icon type="user"/>
              </div>
              <div className="name">{item.fullName}</div>
              <div className="remove-icon" onClick={() => {
                this.unSelectFromSearch(item.userOID)
              }}>
                <Icon type="close"/>
              </div>
              <div className="clear"/>
            </div>
          }
        } else {
          if (_isInSelected(selectedKeysDepData, item.departmentOID)) {
          } else {
            return <div className="selected-person-item" key={item.departmentOID}>
              <div className="type-icon">
                <Icon type="folder"/>
              </div>
              <div className="name">{item.name}</div>
              <div className="remove-icon" onClick={() => {
                this.unSelectFromSearch(item.departmentOID)
              }}>
                <Icon type="close"/>
              </div>
              <div className="clear"/>
            </div>
          }
        }
      })
    }
  }

  //渲染已经选择的人或者部门
  renderSelected(list, selectedKeysDepDataFromSearch) {
    if (list.length < 1 && selectedKeysDepDataFromSearch.length < 1) {
      return (<div className="no-person">
        <Icon type="left"/>
        {messages('components.key540'/*请在左边选择*/)}
      </div>)
    }
    return list.map((item) => {
      let originData = item.props.dataRef.originData;
      if (originData.userOID) {
        return (<div className="selected-person-item"
                     key={originData.userOID}>
          <div className="type-icon">
            <Icon type="user"/>
          </div>
          <div className="name">
            {originData.fullName}
          </div>
          <div className="remove-icon"
               onClick={ () => { this.unSelect(originData.userOID)} }>
            <Icon type="close"/>
          </div>
          <div className="clear"/>
        </div>)
      } else {
        return (<div className="selected-person-item"
                     key={originData.departmentOID}>
          <div className="type-icon">
            <Icon type="folder"/>
          </div>
          <div className="name">
            {originData.name}
          </div>
          <div className="remove-icon"
               onClick={() => {this.unSelect(originData.departmentOID) } }>
            <Icon type="close"/>
          </div>
          <div className="clear"/>
        </div>)
      }
    })
  }


  renderButton() {
    const {renderButton, buttonDisabled, buttonType, title} = this.props;
    if (renderButton) {
      return (
        <Button onClick={this.showModal}
                disabled={buttonDisabled}
                type={buttonType}>{title}</Button>
      )
    } else {
      return (
        <div onClick={!buttonDisabled && this.showModal}
             className="placeholder-class">{title}</div>
      )
    }
  }

  renderSelectTitle = (onlyDep, onlyPerson) => {
    if (onlyDep) {
      return (
        <div className="selected-person-title">
          {messages('components.key541'/*已经选择的部门*/)}
        </div>
      )
    }
    if (onlyPerson) {
      return (
        <div className="selected-person-title">
          {messages('components.key542'/*已经选择的人*/)}
        </div>
      )
    }
    return (
      <div className="selected-person-title">
        {messages('components.key543'/*已经选择的人或部门*/)}
      </div>
    )
  }
  handleCompanyFilterChange = (val) => {
    let companyName = val && val[0] ? val[0].companyName : undefined;
    let companyId = val && val[0] ? val[0].id : undefined;
    let companyOID = val && val[0] ? val[0].companyOID : undefined;
    let depCompany = {
      companyId,
      companyName,
      companyOID
    }
    this.setState({
      depCompany
    },()=>{
      const { depCompany } = this.state;
      //显示模态框的时候再加载
      this.getTenantAllDep(this.props.flagDep, depCompany);
    })
  }
  render() {
    const {userDepName, selectedKeysDepDataFromSearch, selectedKeysDepData, visible, depCompany} = this.state;
    const {onlyPerson, onlyDep, title, tenantMode, enableDepCompany} = this.props;
    const suffix = userDepName ? <Icon type="close-circle" onClick={this.emitEmpty}/> : null;
    let searchInputPlaceholder = messages('components.key544'/*部门名称/部门编码/员工名称*/);
    if (onlyPerson) {
      searchInputPlaceholder = messages('components.key545'/*员工姓名*/);
    }
    if (onlyDep) {
      searchInputPlaceholder = messages('components.key546'/*部门编码/部门名称*/);
    }
    return (
      <div className="select-dep-or-person">
        <div>
          {this.renderButton()}
          <Modal
            width={900}
            className="select-dep-or-person-modal"
            title={title}
            visible={visible}
            onOk={this.handleOk}
            onCancel={this.handleCancel}
            afterClose={this.afterClose}
          >
            <div className="select-person-modal-left">
              {enableDepCompany === "OPEN" && tenantMode && <div className='select-person-company-filter'>
                <div>{messages('components.key895')/*公司过滤*/}</div>
                <Chooser single={true}
                         type="all_company_with_legal_entity"
                         labelKey="companyName"
                         valueKey="companyOID"
                         disabled={!tenantMode}
                         value={depCompany.companyName ? [{
                           companyName: depCompany.companyName,
                           companyOID: depCompany.companyOID
                         }] : undefined}
                         onChange={this.handleCompanyFilterChange}
                         listExtraParams={{}}/>
              </div>}
              <Input
                // 部门名称/部门编码/员工名称
                placeholder={searchInputPlaceholder}
                key={'deporgsearch'}
                prefix={<Icon type="search" className='font-disabled'/>}
                suffix={suffix}
                value={userDepName}
                onChange={this.onChangeUserDepName}
                ref={node => this.userNameDepInput = node}
              />
              {this.renderOrgTreeOrSearchList()}
            </div>
            <div className="select-person-modal-right">
              {this.renderSelectTitle(onlyDep, onlyPerson)}
              <div className="selected-person-wrap">
                {this.renderSelectedFromSearch(selectedKeysDepDataFromSearch, selectedKeysDepData)}
                {this.renderSelected(selectedKeysDepData, selectedKeysDepDataFromSearch)}
              </div>
            </div>
            <div className="clear"/>
          </Modal>
        </div>
      </div>
    );
  }
}

SelectDepOrPerson.propTypes = {
  searchType: React.PropTypes.string,// position 如果传入这个参数，查询岗位信息
  onConfirm: React.PropTypes.func.isRequired,// 点击确认之后的回调：返回结果
  depResList: React.PropTypes.array,//返回的部门列表配置[id,departmentOID]，默认全部属性
  personResList: React.PropTypes.array,//返回的人列表配置[id,userOID,email]等，默认全部属性
  onlyDep: React.PropTypes.bool,//是否只选部门，默认false选择部门与人
  onlyPerson: React.PropTypes.bool,//是否只选人，默认false选择部门与人
  multiple: React.PropTypes.bool,//是否多选.默认true
  title: React.PropTypes.any,//
  buttonType: React.PropTypes.string,
  buttonDisabled: React.PropTypes.bool,
  strictMode: React.PropTypes.bool,//严格模式，公司模式只加载当前公司的人
  loadCompanyOID: React.PropTypes.any,//严格模式，若是传入这个参数，就之加 loadCompanyOID 对应公司的人（注意使用这个参数必须在严格模式下）,如果启用了部门关联公司，使用公司过滤优先于 loadCompanyOID
  depCompany: React.PropTypes.object,//部门关联的公司id，部门是可以关联公司的，部门树 对应 公司树，这个参数就是用来过滤公司的
  renderButton: React.PropTypes.bool,//是否渲染一个button,默认是,主要如果不能再外层包裹一个button，不然再ie上有兼容问题
  externalParams: React.PropTypes.object, //用于渲染树节点时需要的额外参数 add by mengsha.wang@huilianyi.com
  isClickSearchHide: React.PropTypes.bool,//点击搜索结果，是否立即清除关键字
  flagDep: React.PropTypes.any,//部门状态，flag = 1001 全部, 1002 启用, 1003 未启用
  selectedPersons: React.PropTypes.array,//已经选择过的人员  数组里面传人员的实体 {userOID:"",fullName:""}
  selectedDeps: React.PropTypes.array,//已经选择过的部门 数组里面传部门的实体 {departmentOID:"",name:""}
};

SelectDepOrPerson.defaultProps = {
  title: messages('components.key547'/*选择部门或人*/),
  multiple: true,
  onlyDep: false,
  onlyPerson: false,
  buttonType: "",
  buttonDisabled: false,
  renderButton: true,
  strictMode: false,
  loadCompanyOID: false,
  depCompany: {},//集团模式下，加载所有公司，无需默认传入；可以在弹窗中选择；
  externalParams: {},
  isClickSearchHide: true,
  flagDep: 1002,
  selectedPersons: [],
  selectedDeps: [],

};
//严格模式，公司模式只加载当前公司的人
//严格模式，集团模式只加载所有公司的人
function mapStateToProps(state) {
  return {
    enableDepCompany: state.setting.enableDepCompany,
    profile: state.login.profile,
    user: state.login.user,
    tenantMode: state.main.tenantMode,
    company: state.login.company,
  }
}

export default connect(mapStateToProps)(SelectDepOrPerson);

